/*
 * =====================================================================================
 *
 *       Filename:  uart.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  07/03/15 10:03:30
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Andy (gk), andy_y_li@163.com
 *        Company:  RD
 *
 * =====================================================================================
 */

#ifndef _UART_H
#define _UART_H

#include <iostream>
#include <pthread.h>
#include "fifo.h"

#define FIFO_MAX_SIZE (1024 * 2)

using namespace std;

class Uart{
    private:
        int handle;
        int baudRate;
        char *buffer;
        FIFO fifoBuffer;

        pthread_t uart_id;
        pthread_mutex_t mymutex;
        bool stop;
        char *readBuffer;

    public:
        Uart(const char *port, int baudRate = 115200);
        ~Uart();
        char *uart_read();
        bool wait_forString(const char *waitStr, int timeOut);
        void send_command(const char *command);
    private:
        static void* uart_thread(void *arg);
        void uart_td();

};

#endif

